package cn.stylefeng.guns.modular.examination.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.examination.entity.ExaminationResults;
import cn.stylefeng.guns.modular.examination.mapper.ExaminationResultsMapper;
import cn.stylefeng.guns.modular.examination.model.params.ExaminationResultsParam;
import cn.stylefeng.guns.modular.examination.model.result.ExaminationResultsResult;
import  cn.stylefeng.guns.modular.examination.service.ExaminationResultsService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 考试结果 服务实现类
 * </p>
 *
 * @author CHENCHEN
 * @since 2022-07-19
 */
@Service
public class ExaminationResultsServiceImpl extends ServiceImpl<ExaminationResultsMapper, ExaminationResults> implements ExaminationResultsService {

    @Override
    public void add(ExaminationResultsParam param){
        ExaminationResults entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ExaminationResultsParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ExaminationResultsParam param){
        ExaminationResults oldEntity = getOldEntity(param);
        ExaminationResults newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ExaminationResultsResult findBySpec(ExaminationResultsParam param){
        return null;
    }

    @Override
    public List<ExaminationResultsResult> findListBySpec(ExaminationResultsParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ExaminationResultsParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ExaminationResultsParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ExaminationResults getOldEntity(ExaminationResultsParam param) {
        return this.getById(getKey(param));
    }

    private ExaminationResults getEntity(ExaminationResultsParam param) {
        ExaminationResults entity = new ExaminationResults();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
